<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('问题简述')" prop="briefDescriptionOfTheProblem">
            <el-input v-model="form.briefDescriptionOfTheProblem" :placeholder="$t('问题简述')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('时间限制')" prop="timeLimit">
            <el-date-picker
              v-model="form.timeLimit"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('时间限制')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('负责人')" prop="principalId">
            <UserSelect
              v-model="form.principalId"
              :placeholder="$t('项目负责人')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('问题等级')" prop="problemLevel">
            <dictSelect
              v-model="form.problemLevel"
              :clearable="true"
              dictionary="deal_notes_problemLevel"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否处理')" prop="whetherToProcess">
            <el-radio-group v-model="form.whetherToProcess">
              <el-radio-button label="Y">是</el-radio-button>
              <el-radio-button label="N">否</el-radio-button>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否为重大事项')" prop="isItAMajorMatter">
            <dictSelect
              v-model="form.isItAMajorMatter"
              :clearable="true"
              dictionary="sys_yes_no"
            />
            <!--            <el-link v-if="form.isItAMajorMatter === 'Y'" type="primary">重大事项信息</el-link>-->
          </el-form-item>
        </el-col>
        <el-col v-if="form.whetherToProcess === 'Y'" :span="12">
          <el-form-item :label="$t('处理日期')" prop="processingDate">
            <el-date-picker
              v-model="form.processingDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('处理日期')"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="form.whetherToProcess === 'Y'" :span="12">
          <el-form-item :label="$t('处理方式')" prop="howToHandle">
            <el-input v-model="form.howToHandle" :placeholder="$t('处理方式')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('具体描述')" prop="specificDescription">
            <el-input v-model="form.specificDescription" type="textarea" :placeholder="$t('具体描述')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('目前现状')" prop="currentStatus">
            <el-input v-model="form.currentStatus" type="textarea" :placeholder="$t('目前现状')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="yueyin:notes" />
    </div>
  </div>
</template>

<script>
import { saveSysYueyinDealNotes, getSysYueyinDealNotes } from '@/api/sass/yueyin/deal/notes/sysYueyinDealNotes'

export default {
  data() {
    return {
      // 表单参数
      form: {},
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {
        briefDescriptionOfTheProblem: [
          { required: true, message: '必填属性', trigger: 'blur' }
        ],
        timeLimit: [
          { required: true, message: '必填属性', trigger: 'blur' }
        ],
        principalId: [
          { required: true, message: '必填属性', trigger: 'blur' }
        ],
        problemLevel: [
          { required: true, message: '必填属性', trigger: 'blur' }
        ],
        specificDescription: [
          { required: true, message: '必填属性', trigger: 'blur' }
        ],
        currentStatus: [
          { required: true, message: '必填属性', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化数据
    init(data) {
      this.loading = true
      if (data != null && data.id !== undefined) {
        getSysYueyinDealNotes(data.id).then(response => {
          this.form = response.data
          this.loading = false
        })
      } else {
        this.reset()
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,

        dealId: this.$route.query.id,

        briefDescriptionOfTheProblem: undefined,

        specificDescription: undefined,

        timeLimit: undefined,

        principalId: undefined,

        currentStatus: undefined,

        problemLevel: undefined,

        whetherToSendAMessage: undefined,

        whetherToProcess: 'N',

        isItAMajorMatter: undefined,

        processingDate: undefined,

        howToHandle: undefined,

        actId: undefined,

        actStatus: undefined,

        actTitle: undefined,

        remark: undefined,

        createBy: undefined,

        updateBy: undefined,

        createTime: undefined,

        updateTime: undefined,

        delFlag: undefined

      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveSysYueyinDealNotes(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    }

  }

}
</script>
